********************************************************************************
** 	TITLE: c_complier_characteristics.do 
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Table II: Complier Characteristics, Before and After IGNITE

********************************************************************************

		set sortseed 13
use "$output_data/prediction.dta", clear
//Will use the normal definition for stay
	cap drop stay
	gen stay = stay_rec
	cap drop ignite_0
	gen ignite_0 = ignite_0_rec
*************************************
* Estimate 
* Total Estimate Sample
*************************************
preserve
keep if e_sample == 1

egen total_traffic = rowmax(D_dui D_traffic_other)

	foreach c in $design_control $auxiliary_control age_65plus{
		gen `c'_ig = `c'*D_ignite_proxy
	}
	
	
	
	qui reg D_remove_any //creat empty estimate results for formatting
	eststo complier_est
	
	foreach cov in  $auxiliary_control age_65plus D_person D_property D_po ///
			D_drug D_weapons total_traffic  return_3m_hat{
	
	cap gen `cov'_stay = `cov'*stay
	qui ivreghdfe  `cov'_stay ( c.stay#i.D_ignite_proxy  = i.D_remove_any#i.D_ignite_proxy) D_ignite_proxy ///
			$auxiliary_control *_ig if  `cov'>=0 , ///
			cluster(inmate) ///
			a($design_control)
	ereturn display
	mat test = r(table)
	forvalues j=0/1{
		local `cov'`j' = _b[`j'.D_ignite_proxy#c.stay]
		local `cov'`j'_se = _se[`j'.D_ignite_proxy#c.stay]
		
		local `cov'`j': display %8.3f ``cov'`j''
		local `cov'`j'_se: display %8.3f ``cov'`j'_se'
						
		local i=`j'+1
		local p_val`j' =  el(test,4,`i')
		if `p_val`j''<0.01 {
			local star`j'="***"
		}
		if `p_val`j''>=0.01 & `p_val`j''<0.05 {
			local star`j'="**"
		}
		if `p_val`j''>=0.05 & `p_val`j''<0.1 {
			local star`j'="*"
		}
		if `p_val`j''>=0.1 {
			local star`j'=""
		}
						
		local `cov'`j' = "``cov'`j''" /*+"`star`j''"*/
		local `cov'`j'_se = subinstr("(``cov'`j'_se')"," ","",.)
							
		
	}
	
	lincom 0.D_ignite_proxy#c.stay-1.D_ignite_proxy#c.stay
	
	local lintemp = r(estimate)
	local lin: display %8.3f `lintemp'
						
	local linsetemp = r(se)
	local linse: display %8.3f `linsetemp'
						
	local lin_p  =r(p)
						
						
	if `lin_p'<0.01 {
		local star1="***"
	}
	if `lin_p'>=0.01 & `lin_p'<0.05 {
		local star1="**"
	}
	if `lin_p'>=0.05 & `lin_p'<0.1 {
		local star1="*"
	}
	if `lin_p'>=0.1 {
		local star1=""
	}
	
	local linc = "`lin'" + "`star1'"
	local lincse = subinstr("(`linse')"," ","",.)
	
	su `cov' if e(sample)==1
	local `cov'_mean = r(mean)
	local `cov'_mean: display %8.3f ``cov'_mean'
	
	local `cov'_b = "``cov'0'" + "&" + "``cov'1'" + "&" + "`linc'" + "&" +  "``cov'_mean'" 
	local `cov'_se =   "``cov'0_se'" + "&" + "``cov'1_se'" + "&" + "`lincse'" + "&" 
						
	estadd local `cov'_b "``cov'_b'" : complier_est
	estadd local `cov'_se "``cov'_se'" : complier_est
	
	
	}
	
		estout complier_est ///
			using "$tables/table2_complier.tex", style(tex)  ///
			label nobaselevels collabels(none) mlabels(none) /// 
			drop(_cons) ///
			cells(b(star fmt(%8.3f)) se(par fmt(%8.3f))) /// 
			starlevels(* 0.10 ** 0.05 *** 0.01) /// 
			stats(foo1 ///
				D_female_b D_female_se age_17_24_b age_17_24_se age_25_34_b age_25_34_se ///
				age_35_44_b age_35_44_se ///
				age_45_54_b age_45_54_se age_55_64_b age_55_64_se age_65plus_b age_65plus_se ///
				D_Black_b D_Black_se prior_offense_1y_b prior_offense_1y_se ///
				foo D_person_b D_person_se D_property_b D_property_se D_po_b D_po_se ///
				D_drug_b D_drug_se D_weapons_b D_weapons_se ///
				total_traffic_b total_traffic_se /* D_crime_other_b D_crime_other_se  */ ///
				foo2 foo3 ///
				pctebll_b pctebll_se pc_black_b pc_black_se pc_hs_b pc_hs_se ///
				log_med_hhincome_b log_med_hhincome_se D_missing_b D_missing_se ///
				foo4 foo5 return_3m_hat_b return_3m_hat_se, ///
			labels("\textbf{Panel A: Individual Characteristics}" "Female" " " ///
				"Age 18-24" " " ///
				 "Age 25-34" " " ///
				"Age 35-44" " " "Age 45-54" " " "Age 55-64" " "  "Age 65+" " " ///
				"Black" " " "Booked in Past Year" " " ///
				"\textbf{Panel B: Crime Characteristics}" ///
				"Crimes against Persons" " " "Crimes against Property" " " "Crimes against Public Order" " " ///
				"Drug Crimes" " " "Weapons Crimes" " " ///
				"Traffic Crimes" " " /* "Other Crimes" " " */ ///
				" " "\textbf{Panel C: Census Tract Characteristics}" "Share with Elevated Blood Lead Level" " "  ///
				"Share Black" " " "Share High School Graduate or Higher" " " ///
				"Log Median Household Income" " " "Missing Census Tract Information" " " ///
				" " "\textbf{Panel D: Predicted Risk}" "Predicted 3-Month Recidivism" " ")) replace

				restore
